package com.gaosai.staff.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

/**
 * 解析json工具类
 * @author willis
 */
public class ParseJson {

	/**
	 * json解析成hashMap
	 * @Description:TODO
	 * @param jsonString
	 * @return
	 */
	public static  HashMap<String, Object> listKeyMap(String jsonString) {
		HashMap<String, Object> hashmap = new HashMap<String, Object>();
		Gson gson = new Gson();
		hashmap = gson.fromJson(jsonString,new TypeToken<HashMap<String, Object>>(){}.getType());
		return hashmap;
	}
	/**
	 * 解析成<String,String>型的HashMap
	 * @param jsonString
	 * @return
	 */
	public static  HashMap<String, String> listKeyMapString(String jsonString) {
		HashMap<String, String> hashmap = new HashMap<String, String>();
		Gson gson = new Gson();
		hashmap = gson.fromJson(jsonString,new TypeToken<HashMap<String, String>>(){}.getType());
		return hashmap;
	}
	/**
	 * json解析成LinkedHashMap为了和服务器返回的的顺序一致
	 * @param jsonString
	 * @return
	 */
	public static  LinkedHashMap<String, Object> listKeyLinkedMap(String jsonString) {
		LinkedHashMap<String, Object> hashmap = new LinkedHashMap<String, Object>();
		Gson gson = new Gson();
		hashmap = gson.fromJson(jsonString,new TypeToken<LinkedHashMap<String, Object>>(){}.getType());
		return hashmap;
	}
	/**
	 * json解析成ArrayList 里面存放的是HashMap值
	 * @Description:TODO
	 * @param jsonString
	 * @return
	 */
	public static ArrayList<HashMap<String, Object>> listKeyMaps(
			String jsonString) {
		ArrayList<HashMap<String, Object>> ArrayList = new ArrayList<HashMap<String, Object>>();
		Gson gson = new Gson();
		ArrayList = gson.fromJson(jsonString,
				new TypeToken<ArrayList<HashMap<String, Object>>>() {
				}.getType());
		return ArrayList;
	}
	
	public static ArrayList<HashMap<String, String>> listStringKeyMaps(
			String jsonString) {
		ArrayList<HashMap<String, String>> ArrayList = new ArrayList<HashMap<String, String>>();
		Gson gson = new Gson();
		ArrayList = gson.fromJson(jsonString,
				new TypeToken<ArrayList<HashMap<String, String>>>() {
				}.getType());
		return ArrayList;
	}
	
}
